/********************************************************************
 * PROJECT: CSAIR ROST PROJECT.
 * SUPPLIER: FOREVER OPEN SOURCE SOFTWARE INC.
 ********************************************************************
 * FILE: GanttJointHandler.java
 * (C) Copyright Foliage Team 2013, All Rights Reserved.
 ********************************************************************/
package org.foliage.rcp.ui.handlers;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Widget;
import org.foliage.rcp.ui.preference.IGanttSettings;
import org.foliage.rcp.ui.widgets.Gantt;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class GanttJointHandler implements IGanttJointHandler {

	// ----------------------------------------------- 

	private Set members = new HashSet();

	// ----------------------------------------------- 

	public GanttJointHandler(Gantt[] widgets) {
		members.addAll(Arrays.asList(widgets));
	}

	// ----------------------------------------------- 

	@Override
	public void jointHorizontalMovement(int diff) {
		for (Iterator iter = members.iterator(); iter.hasNext();) {
			Gantt gantt = (Gantt) iter.next();
			gantt.moveHorizontal(diff);
		}
	}

	@Override
	public void jointGanttRedrawing() {
		for (Iterator iter = members.iterator(); iter.hasNext();) {
			Gantt gantt = (Gantt) iter.next();
			gantt.redraw();
		}
	}
	
	@Override
	public void jointGanttSettings(IGanttSettings settings) {
		for (Iterator iter = members.iterator(); iter.hasNext();) {
			Gantt gantt = (Gantt) iter.next();
			gantt.setGanttSettings(settings);
		}
	}

	// ----------------------------------------------- 

	@Override
	public void addMember(Widget member) {
		if (!(member instanceof Gantt)) {
			SWT.error(SWT.ERROR_INVALID_ARGUMENT);
		}
		members.add(member);
	}

}
